/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready( function()
{
    initialize();
    $("#btn_ok").click( function ()
            {
                btn_ok_click();
            });
    $("#btn_reset").click( function ()
    {
        btn_reset_click();
    });
    $('.result-area').hide();
    initDatePicker();
});
function initDatePicker()
{
    $( "#datepicker_for" ).datepicker(
        {
            showOn: "button",
            buttonImage: "images/calendar.gif",
            buttonImageOnly: true
        }
    );
    $( "#datepicker_to" ).datepicker(
        {
            showOn: "button",
            buttonImage: "images/calendar.gif",
            buttonImageOnly: true
        }
    );
}
function processUserInfo(user, datefrom, dateto)
{
    var userNameList = $('#user-list');
        userNameList.html('');
    $.get('ChartDataServlet?UserName='+user+'&DateFrom='+datefrom+'&DateTo='+dateto, function(data) {
        var topicList = $('#topic-list');
        topicList.html('');
        
        for(var i =0;i< data.Topics.length ;i++)
            {
                topicList.append('<li><a target="_blank" href="https://twitter.com/search?q=%23'+data.Topics[i]+'">'
                                +data.Topics[i]
                                 + '</a> </li>')
        
            }
    });
   // window.alert(user);
}
function processTopic(topic, datefrom, dateto)
{
    var topicList = $('#topic-list');
        topicList.html('');
     $.get('ChartDataServlet?TopicName='+topic+'&DateFrom='+datefrom+'&DateTo='+dateto, function(data) {
        var userNameList = $('#user-list');
        userNameList.html('');
        
        for(var i=0;i<data.Names.length;i++)
        {
            userNameList.append('<li><a target="_blank" href="https://twitter.com/'+data.Names[i].screen_name+'">'+
                               '<img src="'+data.Names[i].profile_image_url
                            +'" title="'+data.Names[i].user_name+'" />'+
                              '</a> </li>')
        }

    });
//    window.alert(topic);
}

function btn_ok_click()
{
   
    var user = $('#div_user_input').val();
    var topic = $('#div_topic_input').val();
    var location = $('#div_location_input').val();
    
    var datefrom = $('#datepicker_for').val();
    var dateto = $('#datepicker_to').val();
//    if(user)
//    {
//        $('#div_topic_input').val('');
//        $('#div_location_input').val('');
//        processUserInfo(user, datefrom, dateto);
//    }
//    else if(topic)
//    {
//        //$('#div_topic_input').val('');
//        
//        processTopic(topic, datefrom, dateto);
//    }
//    else if(location)
//    {
        processLocation(location, user,topic );
//    }
//    else
//    {
//       window.alert('No input');
//    }
        
        
    $('.result-area').show();
//    $('.graph-0').highcharts({
//        chart: {
//            type: 'bar'
//        },
//        title: {
//            text: 'Fruit Consumption'
//        },
//        xAxis: {
//            categories: ['Apples', 'Bananas', 'Oranges']
//        },
//        yAxis: {
//            title: {
//                text: 'Fruit eaten'
//            }
//        },
//        series: [{
//            name: 'Jane',
//            data: [1, 0, 4]
//        }, {
//            name: 'John',
//            data: [5, 7, 3]
//        }]
//    });
}
function btn_reset_click()
{
    $('.result-area').hide();
    $('#div_user_input').val('');
    $('#div_topic_input').val('');
    $('#div_location_input').val('');
    
}


function initialize() {
        var mapOptions = {
          scaleControl: true,
          center: new google.maps.LatLng(25.746932,-80.368475),
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById('map-canvas'),
            mapOptions);

        var marker = new google.maps.Marker({
          map: map,
          position: map.getCenter()
        });
        var infowindow = new google.maps.InfoWindow();
        infowindow.setContent('<b>মায়ামিতে আছি</b>');
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map, marker);
        });
}